package per.yhh.xxxtsj.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Menu {
    Integer id;
    ArrayList<Children> children = new ArrayList<>();
    String authName;
    @Data
    @AllArgsConstructor
    static class Children {
        Integer id;
        String path;
        String authName;
    }
    private static ArrayList<Menu> rootMenu = new ArrayList<>();
    private static ArrayList<Menu> adminMenu = new ArrayList<>();
    private static ArrayList<Menu> shopMenu = new ArrayList<>();
    private static ArrayList<Menu> commonMenu = new ArrayList<>();
    static {
        Menu usersMenu = new Menu();
        usersMenu.setAuthName("用户管理");
        usersMenu.setId(1);
        usersMenu.getChildren().add(new Menu.Children(1,"users","用户列表"));
        Menu goodsMenu = new Menu();
        Menu goodsMenuC = new Menu();
        goodsMenuC.setAuthName("商品预览");
        goodsMenuC.setId(6);
        goodsMenuC.getChildren().add(new Menu.Children(6,"goods","商品列表"));
        goodsMenu.setAuthName("商品管理");
        goodsMenu.setId(2);
        goodsMenu.getChildren().add(new Menu.Children(4,"categories","商品分类"));
        goodsMenu.getChildren().add(new Menu.Children(6,"goods","商品列表"));
        Menu orderMenu = new Menu();
        orderMenu.setAuthName("订单管理");
        orderMenu.setId(3);
        orderMenu.getChildren().add(new Menu.Children(8,"orders","订单列表"));

        Menu reportsMenu = new Menu();
        reportsMenu.setAuthName("数据统计");
        reportsMenu.setId(4);
        reportsMenu.getChildren().add(new Menu.Children(9,"reports","数据报表"));
        //root和admin可以访问全部内容
        rootMenu.add(usersMenu);
        rootMenu.add(goodsMenu);
        rootMenu.add(orderMenu);
        rootMenu.add(reportsMenu);
        adminMenu.add(usersMenu);
        adminMenu.add(goodsMenu);
        adminMenu.add(orderMenu);
        adminMenu.add(reportsMenu);
        //商户可以访问商品和订单页面
        shopMenu.add(goodsMenu);
        shopMenu.add(orderMenu);
        //普通用户可以访问商品和订单页面
        commonMenu.add(goodsMenuC);
        commonMenu.add(orderMenu);
    }
    public enum menus implements Menus{
        ROOT{
            @Override
            public ArrayList<Menu> returnMenu() {
                return rootMenu;
            }
        },
        Admin{
            @Override
            public ArrayList<Menu> returnMenu() {
                return adminMenu;
            }
        },
        Shop{
            @Override
            public ArrayList<Menu> returnMenu() {
                return shopMenu;
            }
        },
        CommonMenu {
            @Override
            public ArrayList<Menu> returnMenu() {
                return commonMenu;
            }
        }
    }
}

